package com.zretc.controller;

import com.zretc.entity.ReplyComment;
import com.zretc.service.ReplyCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 吴凯
 */
@RestController
@RequestMapping(value = "/replyCommentAdmin")
public class ReplyCommentController {
    @Autowired
    private ReplyCommentService replyCommentService;
    @RequestMapping(value = "/replyCommentSelect/{commendsId}",method = RequestMethod.GET)
    //根据一级评论的编号 查询子评论和子评论对应的用户
    public  List<ReplyComment> commentSelect(@PathVariable(value = "commendsId") String commendsId){
        List<ReplyComment> subComentsByRootCommentId = replyCommentService.getSubComentsByRootCommentId(commendsId);
        return subComentsByRootCommentId;
    }

    @RequestMapping(value = "/replyRootComment",method = RequestMethod.GET)
    //根据一级评论的编号 查询子评论和子评论对应的用户
    public  String replyRootCom(HttpServletRequest request){
        String replyCommentsContent = request.getParameter("replyCommentsContent");
        String rootCommentId = request.getParameter("rootCommentId");
        String rootcommentuserid = request.getParameter("rootcommentuserid");
        String replyUserId = request.getParameter("replyUserId");
        ReplyComment replyComment = new ReplyComment(null,rootCommentId,rootCommentId,Integer.parseInt(rootcommentuserid),
                replyCommentsContent,Integer.parseInt(replyUserId),1,null,null);
        replyCommentService.replyRootComment(replyComment);
        return  "1";
    }
}
